<template>
	<view class="content">
		<view class="cate-right">
			<view class="cate-content" v-for="(item,index) in categoryList" :key="index" @tap="goodsItemClick(item)"
				:data-index="index">
				<image :src="item.rotationImgsJson[0]" mode="aspectFit"></image>
				<view class="conten-right">
					<view class="goodsname">
						<view class="name">{{item.goodsName}}</view>
					</view>
					<view class="goodsprice">
						<view class="price" :style="{'color':templateConfig.page.themeColor}">
							<view>
								<text>￥</text>
								<text class="price-text">{{item.goodsPrice}}</text>
							</view>
							<view class="old-price" v-if="item.scribePrice>0" >
								￥{{item.scribePrice}}
							</view>
							<view class="paynum">销量:{{item.totalSales}}</view>
						</view>
						<view class="cartBox" :style="{'background':templateConfig.page.themeColor}">
							<u-icon name="shopping-cart" color="#ffffff" size="28"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="none_list_box" v-if="categoryList.length===0">
			<u-empty mode="list" ></u-empty>
		</view>
	</view>
</template>

<script>
	import {searchByCategoryGoodsList}  from '../../static/utils/api.js';
	export default {
		data() {
			return {
				templateConfig:uni.getStorageSync('templateConfig') ,
				id: '',
				categoryList: [],
				total: 0,
				page: 1,
			}
		},
		onLoad(options) {
			this.name=options.name
			this.id = options.id
			uni.setNavigationBarTitle({
				title:this.name
			})
		},
		
		onReachBottom() {
			if (this.categoryList.length < this.total) {
				this.page++;
				this.getCategoryList();
			}
		},
		onShow() {
			this.page = 1;
			this.categoryList = [];
			this.getCategoryList()
		},
		methods: {
			
			Topath(route) {
				uni.navigateTo({
					url: route
				})
			},
			goodsItemClick(item) {
				uni.navigateTo({
					url: `/pages/index/detail?id=${item.id}`
				})
			},

			getCategoryList() {
				let data = {
					page:this.page,
					size:10,
					categoryId:this.id
				};
				searchByCategoryGoodsList(data).then(res => {
					if (res.code == 200) {
						if (this.page == 1) {
							this.categoryList = [];
						}
						res.body.forEach((item)=>{
							if(item.rotationImgsJson){
								item.rotationImgsJson=JSON.parse(item.rotationImgsJson)
							}
						})
						let arr = [];
						arr = this.categoryList.concat(res.body);
						this.categoryList = arr;
						this.total = res.total;
					}
				})
			},
		}
	}
</script>

<style lang="less">
	page {
		background-color: #FFFFFF;
	}

	.content {
		width: 100%;
		position: relative;
		padding-bottom: 30rpx;

		.search {
			width: 100%;
			height: 90rpx;
			background-color: #ff5d32;
			display: flex;
			align-items: center;
			position: fixed;
			top: 0;
			left: 0;

			.inp {
				width: 96%;
				// position: absolute;
				// left: 58%;
				// top: 40rpx;
				text-align: center;
				height: 60rpx;
				margin: auto;
				border-radius: 30rpx;
				background-color: #FFFFFF;
			}

			.search-icon {
				position: absolute;
				left: 54%;
				top: 30rpx;
			}
		}

		.cate-right {
			// margin-top: 100rpx;
			margin: 0 auto;
			width: 94%;
			box-sizing: border-box;
			padding: 0rpx 20rpx;
			overflow: auto;

			.cate-content {
				width: 100%;
				height: 220rpx;
				margin-top: 30rpx;
				display: flex;
				border-bottom: 3rpx solid #e9e9e9;
				justify-content: space-between;

				.conten-right {
					height: 100%;
					display: flex;
					width: 72%;
					box-sizing: border-box;
					flex-direction: column;
					justify-content: space-between;
					padding-bottom: 10rpx;
					background-color: #FFFFFF;
				}

				.goodsname {
					width: 100%;
					padding: 6rpx 16rpx;

					.name {
						width: 90%;
						font-size: 30rpx;
						// white-space: nowrap;
						// overflow: hidden;
						// text-overflow: ellipsis;
						display: -webkit-box; //将对象作为弹性伸缩盒子模型显示
						-webkit-box-orient: vertical; //设置或检索伸缩盒对象的子元素的排列方式
						-webkit-line-clamp: 2; //一个块元素显示的文本的行数
						overflow: hidden; //溢出隐藏
						margin-bottom: 20rpx;
					}
				}
				.goodsprice {
					width: 100%;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 6rpx 16rpx;
					.cartBox{
						width: 60rpx;
						height: 60rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						border-radius: 100%;
						background-color: #ff4544;
					}
					.paynum {
						color: #93a1a1;
						font-size: 24rpx;
						margin-left: 16rpx;
						// margin-bottom: 18rpx;
						
					}
					.price {
						color: #ff4544;
						display: flex;
						align-items: center;
						.price-text {
							font-size: 34rpx;
							font-weight: 600;
						}

						.old-price {
							color: #93a1a1;
							font-size: 24rpx;
							margin-left: 16rpx;
							text-decoration: line-through;
						}
					}

					image {
						width: 40rpx;
						height: 40rpx;
					}
				}

				image {
					width: 200rpx;
					height: 200rpx;
					box-sizing: border-box;
					border-radius: 16rpx;
					// border-radius: 8rpx 8rpx 0 0;
				}
			}
		}
	}
</style>
